<?php
$apiKey = 'sk-1eb72a93a0a94256be8871c2c076b344';
$url = 'https://api.deepseek.com/v1/chat/completions';

$data = [
    'model' => 'deepseek-chat',
    'messages' => [
        ['role' => 'user', 'content' => '帮我生成50个有关维修电工的题目及答案，其中包括选择题20题，判断题20题，多选题10题，并附上每道题的解析.直接要完整Excel文件']
    ],
    'temperature' => 0.7,
    'max_tokens' => 500
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($httpCode === 200) {
    $result = json_decode($response, true);
    echo "AI回复：\n" . $result['choices'][0]['message']['content'];
} else {
    echo "请求失败，HTTP状态码: " . $httpCode;
    echo "\n错误响应: " . $response;
}

curl_close($ch);
?>
